<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'category-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => true,
    'htmlOptions' => array(
        'class' => 'form-horizontal',
    ),
        ));
?>
<div class="row-fluid">
    <div class="span12">
        <!--PAGE CONTENT BEGINS-->
        <div class="control-group">
            <label class="control-label">Thứ tự hiện thị</label>
            <div class="controls">
                <?php echo $form->textField($model, "order", array('size' => 60, 'maxlength' => 100, 'class' => 'span5', 'placeholder' => 'Thứ tự hiện thị')); ?>
                <span class="help-inline"><?php echo $form->error($model, 'order'); ?></span>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Tên danh mục sản phẩm</label>
            <div class="controls">
                <?php echo $form->textField($model, "name", array('size' => 60, 'maxlength' => 100, 'class' => 'span5', 'placeholder' => 'Tên menu')); ?>
                <span class="help-inline"><?php echo $form->error($model, 'name'); ?></span>
            </div>
        </div>

        <?php
        $cate = MyFunctionCustom::getCategoryParent();
        //$parent = MyFunctionCustom::getCategoryByParent($model['parent']);
        //echo "<pre>";print_r($menu);
        if (count($cate) > 0):
            ?>
            <div class="control-group">
                <label class="control-label">Danh mục cha</label>
                <div class="controls">
                    <select name="Category[parent]">
                        <option value="0">--</option>
                        <?php
                        foreach ($cate as $k => $m) {
                            if ($k == $model->parent) {
                                echo "<option value='" . $k . "' selected='selected'>" . $cate[$k] . "</option>";
                            } else {
                                echo "<option value='" . $k . "'>" . $cate[$k] . "</option>";
                            }
                        }
                        ?>
                    </select>
                    <span class="help-inline"><?php echo $form->error($model, 'parent'); ?></span>
                </div>
            </div>
        <?php endif; ?>
        <div class="control-group">
            <label class="control-label">Hiện thị ngoài trang chủ</label>
            <div class="controls">
                <?php echo $form->dropDownlist($model, "show_index", array('0' => 'Ẩn', '1' => 'Hiện'), array('id' => 'show_index')); ?>
                <span class="help-inline"><?php echo $form->error($model, 'show_index'); ?></span>
            </div>
        </div>
        <div class="control-group" id="order_index" <?php if ($model['show_index'] == 0) echo 'style="display:none;';else echo ''; ?>">
            <label class="control-label">Thứ tự hiển thị ngoài trang chủ</label>
            <div class="controls">
                <?php echo $form->textField($model, "order_index", array('size' => 60, 'maxlength' => 100, 'class' => 'span5', 'placeholder' => 'Thứ tự hiển thị ngoài trang chủ')); ?>
                <span class="help-inline"><?php echo $form->error($model, 'order_index'); ?></span>
            </div>
        </div> 

        <div class="control-group">
            <label class="control-label">Hiển thị category này khi click vào menu sản phẩm</label>
            <div class="controls">
                <input type="checkbox" name="Category[show_first_product]" style="opacity:1" <?php if($model->show_first_product == '1') echo 'checked="checked"';else echo '';?>>
                <span class="help-inline"><?php echo $form->error($model, 'show_first_product'); ?></span>
            </div>
        </div>

        <div class="control-group">
            <label class="control-label">Trạng thái</label>
            <div class="controls">
                <?php echo $form->dropDownlist($model, "active", array('0' => 'Ẩn', '1' => 'Hiện')); ?>
                <span class="help-inline"><?php echo $form->error($model, 'active'); ?></span>
            </div>
        </div>
        <div class="clear"></div>
        <div class="form-actions">
            <button class="btn btn-info" type="submit">
                <i class="icon-ok bigger-110"></i>
                Submit
            </button>
        </div>
        <!--PAGE CONTENT ENDS-->
    </div><!--/.span-->
</div><!--/.row-fluid-->    
<?php $this->endWidget(); ?>
<script type="text/javascript">
    if(jQuery('#show_index').length){
        jQuery('#show_index').change(function(){
            if(jQuery('#show_index').val() == 1){
                jQuery('#order_index').show();
            }else{
                jQuery('#order_index').hide();
            }
        })
    }
</script>